package com.example.myapplication.util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.myapplication.db.DBHelper;

public class UserAuthUtil {

    public static boolean checkUserCredentials(Context context, String username, String password) {
        DBHelper dbHelper = new DBHelper(context);
        SQLiteDatabase db = dbHelper.getReadableDatabase();

        String[] columns = {"username"};
        String selection = "username=? AND password=?";
        String[] selectionArgs = {username, password};

        Cursor cursor = db.query("users", columns, selection, selectionArgs, null, null, null);

        // 如果cursor移动到了第一行，说明找到了匹配的用户名和密码
        boolean isMatch = cursor.moveToFirst();

        cursor.close();
        db.close();

        return isMatch;
    }
}